package com.bridgeintelligent.tag.customer.service;

import com.bridgeintelligent.tag.constants.bulkload.FileLoadMqMsg;
import com.bridgeintelligent.tag.constants.bulkload.MQConfig;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;

/**
 * Created by JackCheung on 2019/9/22 10:53 PM.
 */
@AllArgsConstructor
@Component
public class CustomerSendMsgHandler {

    protected RocketMQTemplate rocketMQTemplate;

    private ObjectMapper objectMapper;
    /**
     * 客群导出消息推送
     */
    public void sendMsg(String exportId) {

        FileLoadMqMsg fileLoadMqMsg = new FileLoadMqMsg();
        fileLoadMqMsg.setId(exportId);
        try {
            String msg = objectMapper.writeValueAsString(fileLoadMqMsg);
            rocketMQTemplate.convertAndSend(MQConfig.FILE_LOAD_TAG_TOPIC, msg);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}
